//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

namespace Microsoft.Research.ScientificWorkflow.Activities
{
    #region Using Directives

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.ComponentModel;
    using System.Workflow.ComponentModel;
    using System.Collections;
    using System.Collections.Specialized;
    using System.Workflow.ComponentModel.Design;
    using System.ComponentModel.Design;
    using Microsoft.Research.ScientificWorkflow.NetCDF.CSharpAPI;
    using System.Workflow.ComponentModel.Compiler;

    using Microsoft.Research.ScientificWorkflow;
    using Microsoft.Research.ScientificWorkflow.Helpers;
    
    using WorkflowData;
    #endregion

    #region HyperCubeVariableScaler Class

    [Name("Variable Scaler Transform")]
    [Description("Transform for scaling variable values by a specific value")]
    [WorkflowCategory("NetCdf")]
    public class HyperCubeVariableScaler : Activity
    {

        #region Property Definitions

        public static DependencyProperty VariableNameProperty = DependencyProperty.Register("VariableName", 
            typeof(string), typeof(HyperCubeVariableScaler));

        /// <summary>
        /// Name of the variable to be scaled.
        /// </summary>
        [RequiredInputParam]
        [Name("Variable Name")]
        [Description("Name of the variable to be scaled")]
        public string VariableName
        {
            get
            {
                return ((string)(base.GetValue(HyperCubeVariableScaler.VariableNameProperty)));
            }
            set
            {
                base.SetValue(HyperCubeVariableScaler.VariableNameProperty, value);
            }
        }

        public static DependencyProperty ScalarValueProperty = DependencyProperty.Register("ScalarValue", 
            typeof(double), typeof(HyperCubeVariableScaler));

        /// <summary>
        /// Scale value to be used to scale the selected variable
        /// </summary>
        [RequiredInputParam]
        [Name("Scale Value")]
        [Description("Scale value to be used to scale the selected variable")]
        public double ScalarValue
        {
            get
            {
                return ((double)(base.GetValue(HyperCubeVariableScaler.ScalarValueProperty)));
            }
            set
            {
                base.SetValue(HyperCubeVariableScaler.ScalarValueProperty, value);
            }
        }

        public static DependencyProperty InputCubeProperty =
            DependencyProperty.Register("InputCube", typeof(HyperCube), typeof(HyperCubeVariableScaler));

        [RequiredInputParam]
        [Name("In Hyper Cube")]
        [Description("Hyper Cube for Cleaning")]
        public HyperCube InputCube
        {
            get
            {
                return ((HyperCube)(base.GetValue(HyperCubeVariableScaler.InputCubeProperty)));
            }
            set
            {
                base.SetValue(HyperCubeVariableScaler.InputCubeProperty, value);
            }
        }

        public static DependencyProperty ScaledCubeProperty =
            DependencyProperty.Register("ScaledCube", typeof(HyperCube), typeof(HyperCubeVariableScaler));

        [OutputParam]
        [Name("Resultant Hyper Cube")]
        [Description("Sacled cube containing data with scaled values.")]
        public HyperCube ScaledCube
        {
            get
            {
                return ((HyperCube)(base.GetValue(HyperCubeVariableScaler.ScaledCubeProperty)));
            }
            set
            {
                base.SetValue(HyperCubeVariableScaler.ScaledCubeProperty, value);
            }
        }

        #endregion

        #region Overridden Methods

        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
                           
            IHyperCubeTransform xform = new ScalerTransform();

            this.ScaledCube = xform.Transform(this.InputCube, this.ScalarValue, this.VariableName);
            return ActivityExecutionStatus.Closed;
        }

        #endregion

        #region Private Methods

        private void InitializeComponent()
        {
            this.Name = "HyperCubeVariableScaler";
        }
        
        #endregion

    }

    #endregion

}
